<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="./Public/Admin/Bootstrap/Css/bootstrap.min.css" />
	<script type="text/javascript" src='./Public/Admin/js/jquery-1.8.2.min.js'></script>
	<!-- <script type="text/javascript" src='./Public/Admin/uploadify/jquery.uploadify.min.js'></script> -->
	<!-- 处理上传类的js、css -->
	<!-- <script type="text/javascript" src="./Public/Admin/uploadify/jquery-1.8.2.min.js"></script> -->
	<script type="text/javascript" src="./Public/Admin/uploadify/jquery.uploadify.min.js"></script>
	<link href="./Public/Admin/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	<!-- 引入编辑器 -->
	<script type="text/javascript" charset="utf-8" src="./Public/ueditor1_4_3/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="./Public/ueditor1_4_3/ueditor.all.min.js"> </script>
	<script type="text/javascript" charset="utf-8" src="./Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!-- 处理商品属性及规格的js -->
	<script type="text/javascript" src="./Public/Admin/js/goods.js"></script>
	
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	li{
    		list-style-type: none;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
	</style> 
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">
	<form action="" method='post' enctype="multipart/form-data">
		<fieldset>
			<legend>添加商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="cid">
								<option value="0" tid='0'>-请选择-</option>
								{{foreach from="$cateData" value="$v"}}
								<option value="{{$v['cid']}}" tid="" {{if value="$oldData['cid']==$v['cid']" }} selected {{endif}}>{{$v['_name']}}</option>
								{{endforeach}}
							</select>
						</td>
					</tr>
					
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="bid">
								<option value="0">-请选择-</option>
								{{foreach from="$brandData" value="$v"}}
								<option value="{{$v['bid']}}" {{if value="$oldData['bid']==$v['bid']" }} selected {{endif}}>{{$v['bname']}}</option>
								{{endforeach}}
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="{{$oldData['gname']}}" />
						</td>
					</tr>
					<tr class="info">
						<td>商品货号</td>
						<td>
							<input type="text" name='gnumber' value="{{$oldData['gnumber']}}" />
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value="{{$oldData['unit']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='marketprice' value="{{$oldData['marketprice']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice' value="{{$oldData['shopprice']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click' value="{{$oldData['click']}}"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
			<!-- 这儿先是采用循环的方式进行循环出来，然后上面所属分类有所改变的话这儿再继续进行 全部删除，然后在进行异步添加。 -->
				{{foreach from="$attrData" key="$k" value="$v"}}
				<tr class="info">
					<td>{{$v['taname']}}</td>
					<td>
						<select name="attr[{{$v['taid']}}]}" id="">
							<option value="0">请选择</option>
							{{foreach from="$v['tavalue']" value="$value"}}
							<option value="{{$value}}" {{if value="$v['gtvalue']==$value" }} selected {{endif}}>{{$value}}</option>
							{{endforeach}}
						</select>
					</td>
				</tr>
				{{endforeach}}
					<!-- <td><select name="attr['+v.taid+']" id=""><option value="0">请选择</option>';
						$.each(v.tavalue,function(kk,vv){
							attr +=	'<option value="'+vv+'">'+vv+'</option>';
							});
						attr +='</select></td></tr>'; -->
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
			{{foreach from="$specData" value="$v"}}
				<tr class="info">
					<td>{{$v['taname']}}</td>
					<td>
						<select name="spec[{{$v['taid']}}][color][]" id="">
							<option value="">请选择</option>
							{{foreach from="$v['tavalue']" value="$value"}}
							<option value="{{$value}}" {{if value="$v['gtvalue']==$value" }} selected {{endif}}>{{$value}}</option>
							{{endforeach}}
						</select>
					</td>
					<td>附加价格</td>
					<td>
						<input type="text" name="spec[{{$v['taid']}}][added][]" id="" value="{{$v['added']}}" />
					</td>
					<td>
						<a href="javascript:;" class="btn btn-success addSpec">增加</a>
					</td>
				</tr>
				{{endforeach}}
				<!-- 这儿是接收异步添加的spec 且还有相同规格名的添加删除功能-->
			</table>
			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td id="thumbBox">
						<li url="{{$oldData['pic']}}">
							<img src="{{$oldData['pic']}}" alt="" />
					 		<a href="javascript:;" id="aclose" style="color:red">X</a>
					 		<input type="hidden" name="pic" value="{{$oldData['pic']}}" />
						</li>
					</td>
					<td id="hideImg" style="display: none;">
						<input id="file3" type="file" multiple="true" name="photos3"/>
						<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
					    <script type="text/javascript">
						    $(function() {
						        $('#file3').uploadify({
						            'formData'     : {//POST数据
						                '<?php echo session_name();?>' : '<?php echo session_id();?>',
						            },
						            'fileTypeDesc' : '上传文件',//上传描述
						            'fileTypeExts' : '*.jpg;*.png;*.jpeg;*.gif',   //允许上传的类型
						            'swf'      : './Public/Admin/uploadify/uploadify.swf', //必须得存在的swf
						            'uploader' : "{{U('ajaxUpload')}}",  //异步上传逻辑处理路径
						            'buttonText':'选择文件',
						            'fileSizeLimit' : '2000KB',
						            'uploadLimit' : 1000,//上传文件数
						            'width':65,
						            'height':25,
						            'successTimeout':10,//等待服务器响应时间
						            'removeTimeout' : 0.2,//成功显示时间
						            'onUploadSuccess' : function(file, data, response) {
						                data=$.parseJSON(data);
						                // console.log(data);
						                var imageUrl = data.image?data.url:'./Upload/image/default.png';//这是上传图片的存储路径，三元表达式，如果有图片路径，那使用的是定义的图片路径，否则使用默认的图片路径和格式。
						                console.log(imageUrl);
						               var li = '<li url="'+data.path+'" style="float:right ;"><img src="'+data.path+'" style="width:150px;heigh:150px;float:right;"/>';
										 li += '<input type="hidden" name="pic" id="" value="'+data.path+'" />';
										 li += '<a href="javascript:;" class="delImg3" style="color:red">X</a></li>';
						                $("#pic-list3").prepend(li);
						            }

						        });
						    });
						</script>
						 
						 	<!-- 异步删除图片-->
						<script type="text/javascript">
							$(function(){
								$(".delImg3").live("click",function(){
									var url = $(this).parents("li").attr("url");
									var _this=$(this);
									$.ajax({
										type:"post",
										url:"{{U('ajaxDelImg')}}",
										data:{url:url},
										dataType:"json",
										success:function(data){
											if(data==1){
												_this.parents("li").remove();
											}
										}
									});
								})
							})
						</script>
					</td>
					<td id='pic-list3'></td>
				</tr>
			</table>
			<script type="text/javascript">
				$(function(){
					$('#aclose').click(function(){
						var url = $(this).parents("li").attr("url");
						$.ajax({
							type:"post",
							url:"{{U('ajaxDelImg1')}}",
							data:{url:url},
							dataType:"json",
							success:function(data){
								if(data==1){
									$('#thumbBox').remove();
									$('#hideImg').show();
								}
							}
						});
					})
				})
			</script>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td id="AllBox">
						<input id="file2" type="file" multiple="true" name="photos2"/>
						<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
						<script type="text/javascript">
							 $(function() {
						        $('#file2').uploadify({
						            'formData'     : {//POST数据
						                '<?php echo session_name();?>' : '<?php echo session_id();?>',
						            },
						            'fileTypeDesc' : '上传文件',//上传描述
						            'fileTypeExts' : '*.jpg;*.png;*.jpeg;*.gif',   //允许上传的类型
						            'swf'      : './Public/Admin/uploadify/uploadify.swf', //必须得存在的swf
						            'uploader' : "{{U('ajaxUpload1')}}",  //异步上传逻辑处理路径
						            'buttonText':'选择文件',
						            'fileSizeLimit' : '2000KB',
						            'uploadLimit' : 1000,//上传文件数
						            'width':65,
						            'height':25,
						            'successTimeout':10,//等待服务器响应时间
						            'removeTimeout' : 0.2,//成功显示时间
						            'onUploadSuccess' : function(file, data, response) {
						                data=$.parseJSON(data);
						                // console.log(data);
						                var imageUrl = data.image?data.url:'./Upload/image/default.png';//这是上传图片的存储路径，三元表达式，如果有图片路径，那使用的是定义的图片路径，否则使用默认的图片路径和格式。
						                console.log(imageUrl);
						               var li = '<li url="'+data.path+'" style="float:right ;"><img src="'+data.path+'" style="width:150px;height:150px;float:right;"/>';
										 li += '<input type="hidden" name="big[]" id="" value="'+data.newpath+'" /><input type="hidden" name="medium[]" id="" value="'+data.newPath1+'" /><input type="hidden" name="small[]" id="" value="'+data.newPath2+'" />';
										 li += '<a href="javascript:;" class="delImg1" style="color:red">X</a></li>';
						                $("#photo-list").prepend(li);
						            }
						        });
							})
						</script>
						
						 	<!-- 异步删除图片-->
						<script type="text/javascript">
							$(function(){
								$(".delImg1").live("click",function(){
									var url = $(this).parents("li").attr("url");
									var _this=$(this);
									$.ajax({
										type:"post",
										url:"{{U('ajaxDelImg1')}}",
										data:{url:url},
										dataType:"json",
										success:function(data){
											if(data==1){
												_this.parents("li").remove();
											}
										}
									});
								})
							})
						</script>
					</td>
					<td id="goodsImg">
						 	{{foreach from="$detailData['big']" key="$k" value="$v"}}
						 		<div class="imgBox" style="float: left;">
							 		<a href="" url="{{$v}}"><img src="{{$v}}" alt="" style="width: 200px;height: 200px;" /></a>
							 		<a href="javascript:;" class="aclose" style="color:red">X</a>
							 		<a href=""><input type="hidden" name="big[]" id="" value="{{$v}}"><input type="hidden" name="medium[]" id="" value="{{$detailData['medium'][$k]}}"><input type="hidden" name="small[]" id="" value="{{$detailData['small'][$k]}}"></a>
						 		</div>
						 	{{endforeach}}
					</td>
			        <script type="text/javascript">
						$('.aclose').live("click",function(){
							var url = $(this).prev("a").attr("url");
							// console.log(url);
							var _this=$(this);
							$.ajax({
								type:"post",
								url:"{{U('ajaxDelImg2')}}",
								data:{url:url},
								dataType:"json",
								success:function(data){
									// console.log(data);
									if(data==1){
										_this.prev("a").remove();
										_this.next('a').remove();
										_this.remove();
									}
								}
							});
						});
					</script>
						
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
					<script id="editor" type="text/plain" style="width:100%;height:500px;" name="intro">{{$detailData['intro']}}</script>
		    		<script>
		        		var ue = UE.getEditor('editor');
		   			</script>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
					<script id="ed" type="text/plain" style="width:100%;height:500px;" name="service" value="">{{$detailData['service']}}</script>
		    		<script>
		        		var ue = UE.getEditor('ed');
		   			</script>
				</tr>
			</table>
			<input type="hidden" name="gid" value="{{$oldData['gid']}}" />
			<input type="submit" value="确认修改" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>
